﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Vectrosity;

public class vectorLine :MonoBehaviour
{

	
	
	
	/*
	Queue<timedPoints> pointQueue;
	Queue<timedPoints> partnerPointQueue;
	
	static Material lineMaterial;
	Vector3 pPoint;
	float zPos = 5;
	
	void Start()
	{
		pointQueue = new Queue<timedPoints>();
		partnerPointQueue = new Queue<timedPoints>();
		CreateLineMaterial();
	}
	
	void Update()
	{
		if(Input.GetMouseButtonDown(0))
		{
			Vector3 camPt = camera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,Input.mousePosition.y,zPos));
			pointQueue.Enqueue(new timedPoints(camPt,Time.timeSinceLevelLoad));
			networkView.RPC("createPoint",RPCMode.Others,camPt.x, camPt.y, false);
			pPoint = camPt;
		}
		else if(Input.GetMouseButton(0))
		{
			Vector3 camPt = camera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,Input.mousePosition.y,zPos));
			if(pPoint != camPt)
			{
				pPoint = camPt;
				pointQueue.Enqueue(new timedPoints(camPt,Time.timeSinceLevelLoad));
				networkView.RPC("createPoint",RPCMode.Others,camPt.x, camPt.y, false);
			}
		}
		
		if(Input.GetMouseButtonUp(0))
		{
			Vector3 camPt = camera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,Input.mousePosition.y,zPos));
			pPoint = camPt;
			timedPoints point = new timedPoints(camPt,Time.timeSinceLevelLoad);
			point.isEndPt = true;
			pointQueue.Enqueue(point);
			networkView.RPC("createPoint",RPCMode.Others,camPt.x, camPt.y, true);
		}
	}
	
	static void CreateLineMaterial() {
		if( !lineMaterial ) {
			lineMaterial = new Material( "Shader \"Lines/Colored Blended\" {" +
				"SubShader {Tags { \"RenderType\"=\"Opaque\" } Pass { " +
				"    Blend SrcAlpha OneMinusSrcAlpha " +
				"    ZWrite On Cull Off Fog { Mode Off } " +
				"    BindChannels {" +
				"      Bind \"vertex\", vertex Bind \"color\", color }" +
				"} } }" );
			lineMaterial.hideFlags = HideFlags.HideAndDontSave;
			lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave;
		}
	}
	
	void OnPostRender() {
		GL.Begin( GL.LINES );
		
		lineMaterial.SetPass(0);
		
		Vector3 prevPoint = Vector3.zero;
		bool reachedEnd = true;
		float timeNow = Time.timeSinceLevelLoad;
		
		foreach(timedPoints pt in pointQueue)
		{
			GL.Color( new Color(1f,1f,1f,2.5f - (timeNow - pt.time)));
			if(reachedEnd)
			{
				reachedEnd = false;
				GL.Vertex(pt.point);
			}
			else
				GL.Vertex(prevPoint);
			
			GL.Vertex(pt.point);
			prevPoint = pt.point;
			
			if(pt.isEndPt)
				reachedEnd = true;
		}
		reachedEnd = true;
		foreach(timedPoints pt in partnerPointQueue)
		{
			GL.Color( new Color(1f,1f,1f,2.5f - (timeNow - pt.time)));
			if(reachedEnd)
			{
				reachedEnd = false;
				GL.Vertex(pt.point);
			}
			else
				GL.Vertex(prevPoint);
			
			GL.Vertex(pt.point);
			prevPoint = pt.point;
			
			if(pt.isEndPt)
				reachedEnd = true;
		}
		GL.End();
		
		
	}
	
	[RPC]
	void createPoint(float x, float y, bool isEnd)
	{
		Vector3 tmpVec = new Vector3(x,y,-zPos);
		partnerPointQueue.Enqueue(new timedPoints(tmpVec,Time.timeSinceLevelLoad,isEnd));
	}*/
}
